package com.teacold.customdemo.chapter_seven;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.BitmapShader;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Shader;
import android.util.AttributeSet;
import android.view.View;

import com.teacold.customdemo.R;

public class BitmapShaderView extends View {
    private Paint mPaint;
    private Bitmap bitmap;


    public BitmapShaderView(Context context) {
        super(context);
        mPaint=new Paint();
        bitmap=BitmapFactory.decodeResource(getResources(), R.mipmap.menu_five);
        mPaint.setShader(new BitmapShader(bitmap,Shader.TileMode.REPEAT,Shader.TileMode.REPEAT));
//        Shader.TileMode.MIRROR//镜面
    }

    public BitmapShaderView(Context context, AttributeSet attrs) {
        this(context);
    }

    public BitmapShaderView(Context context, AttributeSet attrs, int defStyleAttr) {
        this(context, attrs);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        //getWidth()用于获取控件宽度，getHeight()用于获取控件高度
        canvas.drawRect(0,0,getWidth(),getHeight(),mPaint);
    }


}
